from django.db import models
from ehmn.models import Geneloc 

class Pathway(models.Model):
    pathid = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)
    category = models.CharField(max_length=100, blank=True)
    def __str__(self):
      return self.name
    class Meta:
        db_table = u'pathway2'

class Reaction(models.Model):
    reactionid = models.CharField(max_length=6, primary_key=True)
    pathway = models.ForeignKey(Pathway)
    reversibility = models.CharField(max_length=1, blank=True)
    main_compound = models.CharField(max_length=100, blank=True)
    equation = models.CharField(max_length=300, blank=True)
    eq_in_id = models.CharField(max_length=150, blank=True)
    comment = models.CharField(max_length=600, blank=True)
    def __str__(self):
      return self.reactionid
    class Meta:
        db_table = u'reaction2'
#        ordering = ('pathway', 'reactionid',)

class Compound(models.Model):
    compoundid = models.CharField(max_length=6, primary_key=True)
    name = models.CharField(max_length=300, blank=True)
    formula = models.CharField(max_length=300, blank=True)
    keggid = models.CharField(max_length=6, blank=True)
    empid = models.CharField(max_length=6, blank=True)
    cas = models.CharField(max_length=100, blank=True)
    pubchem = models.CharField(max_length=8, blank=True)
    chebi = models.CharField(max_length=6, blank=True)
    hmdb = models.CharField(max_length=9, blank=True)
    smile = models.CharField(max_length=1000, blank=True)
    inchi = models.CharField(max_length=1000, blank=True)
    def __str__(self):
      return self.compoundid
#    def __unicode__(self):
 #     return u'%s %s' (self.compoundid, self.name)
    class Meta:
        # the db-table meta class define the table name
        db_table = u'compound2'

class Gene(models.Model):
    geneid = models.CharField(max_length=10,primary_key=True)
    name = models.CharField(max_length=25, blank=True)
    synonym = models.CharField(max_length=200,blank=True)
    chromosome=models.CharField(max_length=8,blank=True)
    maploc=models.CharField(max_length=40,blank=True)
    description=models.CharField(max_length=300,blank=True)
    fullname=models.CharField(max_length=200,blank=True)
    hgnc=models.CharField(max_length=5,blank=True)
    ensembl=models.CharField(max_length=20,blank=True)
    omim=models.CharField(max_length=300,blank=True)
    unigene=models.CharField(max_length=100,blank=True)
    gi=models.CharField(max_length=400,blank=True)
    hprd=models.CharField(max_length=40,blank=True)
    uniprot=models.CharField(max_length=550,blank=True)
    altprotein=models.CharField(max_length=400,blank=True)
    def __str__(self):
      return self.name
    class Meta:
        db_table = u'gene2'

class Rea_comp(models.Model):
#serial primary key generated automatically
    SUB_CHOICES = (
        ('S', 'Substrate'),
        ('P', 'Product'),
        )
    reaction = models.ForeignKey(Reaction)
    compound = models.ForeignKey(Compound)
    sub_pro = models.CharField(max_length=1, choices=SUB_CHOICES)
    maincompound = models.CharField(max_length=1, blank=True)
    coefficient = models.CharField(max_length=3, blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.compound)
    class Meta:
        db_table = u'rea_comp2'

class Rea_gene(models.Model):
    reaction = models.ForeignKey(Reaction)
    gene = models.ForeignKey(Gene)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.gene)
    class Meta:
        db_table = u'rea_gene2'

class Rea_ec(models.Model):
    reaction = models.ForeignKey(Reaction)
    enzyme = models.CharField(max_length=20)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.enzyme
    class Meta:
        db_table = u'rea_ec2'

class Gene_ec(models.Model):
    gene = models.ForeignKey(Gene)
    enzyme = models.CharField(max_length=20)
#    def __unicode__(self):
#      return u'%s %s' (self.gene, self.enzyme)
    class Meta:
        db_table = u'gene_ec2'

class Met_link(models.Model):
    com1 = models.ForeignKey(Compound, related_name = "substrate")
    com2 = models.ForeignKey(Compound, related_name = "product")
    rea=models.ForeignKey(Reaction)
    pathway=models.ForeignKey(Pathway, blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.gene, self.enzyme)
    class Meta:
        db_table = u'met_link2'

class Location(models.Model):
    id = models.IntegerField(primary_key=True)
    goid = models.CharField(max_length=10)
    des = models.CharField(max_length=30)
    abs = models.CharField(max_length=4)
    def __str__(self):
      return self.des
    class Meta:
        db_table = u'location2'

class Realoc(models.Model):
    rea = models.ForeignKey(Reaction)
    loc = models.ForeignKey(Location)
    class Meta:
        db_table = u'realoc2'
    class Admin:
        list_display = ('rea', 'loc',)

class Tissue(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)
    def __str__(self):
      return self.name
    class Meta:
        db_table = u'tissue2'

class Rea_tissue(models.Model):
    reaction = models.ForeignKey(Reaction)
    tissue = models.ForeignKey(Tissue)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.reaction
    class Meta:
        db_table = u'rea_tissue2'
